define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {

	$scope.form.id=params.id;
		
	//查询上课时间数据
		httpService.post(app.urls.course_time_selectById,$scope.form,function(data){
			if("0000" === data.code){
				$scope.form.startH = data.data.start_time.split(':')[0];
				$scope.form.startM = data.data.start_time.split(':')[1];
				$scope.form.endH = data.data.end_time.split(':')[0];
				$scope.form.endM = data.data.end_time.split(':')[1];
			}else{
				alert(data.msg);
			}
		});

	var hourArray = [];
	for (var i = 6; i < 24; i++) {
		var dataH = {};
		if (i < 10){
			dataH.name= i;
    		dataH.value = '0'+i;
		}else {
			dataH.name= i;
    		dataH.value = ''+i;
		}
		hourArray.push(dataH);
	}
    
	var minuteArray = [];
	for (var i = 0; i < 60; i++) {
		var dataH = {};
 		if (i < 10){
			dataH.name= i;
    		dataH.value = '0'+i;
		}else {
			dataH.name= i;
    		dataH.value = ''+i;
		}
		minuteArray.push(dataH);
	}
 
	$scope.hourList = hourArray;
	$scope.minuteList = minuteArray;
 	$scope.saveForm = function(){
		if($scope.formCheck()){
			$scope.form.start_time=$scope.form.startH + ':' + $scope.form.startM;
			$scope.form.end_time=$scope.form.endH + ':' + $scope.form.endM;
			var interval;
			if($scope.form.startH == $scope.form.endH){
				interval = $scope.form.endM - $scope.form.startM ;
			}else if($scope.form.startH < $scope.form.endH){
				interval=(60 - $scope.form.startM)+$scope.form.endM;
			}
			if($scope.form.startH == $scope.form.endH  &&  $scope.form.startM == $scope.form.endM){
				alert("开始时间不能等于结束时间");
				return ;
			}else if($scope.form.startH > $scope.form.endH){
				alert("开始时间不能大于结束时间");
				return ;
			}else if($scope.form.startH == $scope.form.endH  &&  $scope.form.startM > $scope.form.endM){
				alert("开始时间不能大于结束时间");
				return ;
			}
		
			httpService.post(app.urls.course_time_update,$scope.form,function(data){
				if("0000" === data.code){
					eventBusService.publish("content.page.reload",data.data);
					eventBusService.publish("modal.page.close",{});
				}else{
					alert(data.msg);
				}
			});
		}
	}
}}});